﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DesignPattern.StructureType.Component
{
    public class Folder : AbstractFile
    {
        public IList<AbstractFile> list;

        public Folder(string name) :base(name,FileType.Folder)
        {
            list = new List<AbstractFile>();
        }

        public void Add(AbstractFile file)
        {
            list.Add(file);
        }

        public void Remove(AbstractFile file)
        {
            list.Remove(file);
        }

        public override void Show()
        {
            ConsoleShow(this);
        }

        void ConsoleShow(Folder file)
        {
            Console.WriteLine("Type=" + file.Type.ToString() + ";Name=" + file.Name);
            foreach (var item in file.list)
            {
                if (item.Type == FileType.File)
                {
                    item.Show();
                }
                else
                {
                    this.ConsoleShow(item as Folder);
                }
            }
        }

        void ConsoleShow()
        {
            foreach (var item in this.list)
            {
                if (item.Type == FileType.File)
                {
                    item.Show();
                }
                else
                {
                    this.ConsoleShow(item as Folder);
                }
            }
        }


        public override void Click()
        {
            foreach (var item in this.list)
            {
                Console.WriteLine("Type=" + item.Type.ToString() + ";Name=" + item.Name);
            }
        }
    }
}
